//
//  MessageTopTableViewCell.m
//  BGM
//
//  Created by liuqin on 2018/12/4.
//  Copyright © 2018 com.alirtc.demo. All rights reserved.
//

#import "MessageTopTableViewCell.h"
#import "Common.h"
#import "UIImageView+WebCache.h"
@interface MessageTopTableViewCell()
@property (nonatomic, strong)UIImageView *headImage;
@property (nonatomic, strong)UILabel *nameLabel;
@property (nonatomic, strong)UILabel *ageLabel;
@property (nonatomic, strong)UIView *infoView;


@end

@implementation MessageTopTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self != nil) {
        self.backgroundColor = [UIColor whiteColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.headImage = [[UIImageView alloc]initWithFrame:CGRectMake(30, 10, 50, 50)];
        [self.headImage setImage:[UIImage imageNamed:@"headImage"]];
        self.headImage.layer.cornerRadius = 50/2;
        self.headImage.layer.masksToBounds = YES;
        self.headImage.contentMode = UIViewContentModeScaleAspectFit;
        [self addSubview:self.headImage];
        
        self.nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(100, 10, SCREENW-120, 30)];
        self.nameLabel.font = [UIFont systemFontOfSize:16];
        [self addSubview:self.nameLabel];
        
        self.infoView = [[UIView alloc]initWithFrame:CGRectMake(95, 40, SCREENW-120, 30)];
        [self addSubview:self.infoView];
        
        UILabel *line = [[UILabel alloc]initWithFrame:CGRectMake(15, 69, SCREENW-30, 0.3)];
        line.alpha = 0.3;
        line.backgroundColor = [UIColor grayColor];
        [self addSubview:line];
        
    }
    return self;
}

- (void)reloadTopView:(NSDictionary *)dic userType:(NSString *)type{
    if (dic.count==0) {
        return;
    }
    if([type isEqualToString:@"0"]){
        [self userMsgDic:dic];
    }else{
        [self publicMsgDic:dic];
    }
   
    
}

- (void)userMsgDic:(NSDictionary *)dic{
    [self.headImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[dic objectForKey:@"headImage"]]] placeholderImage:[UIImage imageNamed:@"headImage"]];
    self.nameLabel.text = [NSString stringWithFormat:@"%@",[dic objectForKey:@"userName"]];
    
    UIButton *sexBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 50, 20)];
    sexBtn.layer.masksToBounds = YES;
    sexBtn.layer.cornerRadius = 10;
    sexBtn.titleLabel.font = [UIFont systemFontOfSize:11];
    [sexBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.infoView addSubview:sexBtn];
    NSString *str = [NSString stringWithFormat:@"%@",[dic objectForKey:@"gender"]];
    if ([str isEqualToString:@"1"]) {//男
        sexBtn.backgroundColor = bgmColor(68, 209, 208);
        [sexBtn setImage:[UIImage imageNamed:@"sex_1"] forState:UIControlStateNormal];
    }else{
        sexBtn.backgroundColor = bgmColor(251, 119, 123);
        [sexBtn setImage:[UIImage imageNamed:@"sex_2"] forState:UIControlStateNormal];
    }
    str = [NSString stringWithFormat:@"%@",[dic objectForKey:@"birthday"]];
    [sexBtn setTitle:str forState:UIControlStateNormal];
    
    NSMutableArray *array = [[NSMutableArray alloc]init];
    str = [NSString stringWithFormat:@"%@",[dic objectForKey:@"city"]];
    [array addObject:str];
    str = [NSString stringWithFormat:@"%@",[dic objectForKey:@"industry"]];
    [array addObject:str];
    NSArray *personalLabel = [dic objectForKey:@"personalLabel"];
    [array addObjectsFromArray:personalLabel];
    float x = sexBtn.frame.origin.x+sexBtn.frame.size.width+5;
    for (int i = 0;i<1;i++) {
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(x+55*i, 0, 50, 20)];
        label.textColor = bgmgrayColor;
        label.font = [UIFont systemFontOfSize:11];
        label.backgroundColor = bgmColor(250, 241, 194);
        label.text = [array objectAtIndex:i];
        label.layer.masksToBounds = YES;
        label.layer.cornerRadius = 10;
        label.textAlignment = NSTextAlignmentCenter;
        label.layer.borderColor = [bgmColor(250, 223, 93) CGColor];
        label.layer.borderWidth = 1;
        [self.infoView addSubview:label];
    }
    
}

- (void)publicMsgDic:(NSDictionary *)dic{
    [self.headImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[dic objectForKey:@"uheadImage"]]] placeholderImage:[UIImage imageNamed:@"headImage"]];
    self.nameLabel.text = [NSString stringWithFormat:@"%@",[dic objectForKey:@"uname"]];
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 50, 20)];
    label.textColor = bgmgrayColor;
    label.font = [UIFont systemFontOfSize:11];
    label.backgroundColor = bgmColor(250, 241, 194);
    label.layer.masksToBounds = YES;
    label.layer.cornerRadius = 10;
    label.textAlignment = NSTextAlignmentCenter;
    label.layer.borderColor = [bgmColor(250, 223, 93) CGColor];
    label.layer.borderWidth = 1;
    label.text = [NSString stringWithFormat:@"%@",[dic objectForKey:@"ucity"]];
    [self.infoView addSubview:label];
    
    
    UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(60, 0, 50, 20)];
    label1.textColor = bgmgrayColor;
    label1.font = [UIFont systemFontOfSize:11];
    label1.backgroundColor = bgmColor(250, 241, 194);
    label1.layer.masksToBounds = YES;
    label1.layer.cornerRadius = 10;
    label1.textAlignment = NSTextAlignmentCenter;
    label1.layer.borderColor = [bgmColor(250, 223, 93) CGColor];
    label1.layer.borderWidth = 1;
    label1.text = @"公益";
    [self.infoView addSubview:label1];
    
    UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(120, 0, 60, 20)];
    label2.textColor = bgmgrayColor;
    label2.font = [UIFont systemFontOfSize:11];
    label2.backgroundColor = bgmColor(250, 241, 194);
    label2.layer.masksToBounds = YES;
    label2.layer.cornerRadius = 10;
    label2.textAlignment = NSTextAlignmentCenter;
    label2.layer.borderColor = [bgmColor(250, 223, 93) CGColor];
    label2.layer.borderWidth = 1;
    label2.text = [NSString stringWithFormat:@"%@",[dic objectForKey:@"laber"]];
    [self.infoView addSubview:label2];
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
